package com.ruoyi.web.controller.subsidy;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.subsidy.domain.AreaTreeVo;
import com.ruoyi.subsidy.domain.SysStrativeArea;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.subsidy.domain.vo.SysStrativeAreaVo;
import com.ruoyi.subsidy.domain.bo.SysStrativeAreaBo;
import com.ruoyi.subsidy.service.ISysStrativeAreaService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行政区域
 *
 * @author nbacheng
 * @date 2025-08-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@SaIgnore
@RequestMapping("/subsidy/strativeArea")
public class SysStrativeAreaController extends BaseController {

    private final ISysStrativeAreaService iSysStrativeAreaService;

    /**
     * 查询行政区域列表
     */
   // @SaCheckPermission("subsidy:strativeArea:list")
    @GetMapping("/list")
    public TableDataInfo<SysStrativeAreaVo> list(SysStrativeAreaBo bo, PageQuery pageQuery) {
        return iSysStrativeAreaService.queryPageList(bo, pageQuery);
    }

    @SaIgnore
    @GetMapping("/listTree")
    public List<AreaTreeVo> queryAreaTree(SysStrativeAreaBo bo) {
        return iSysStrativeAreaService.queryAreaTree(bo);
    }



    /**
     * 导出行政区域列表
     */
   // @SaCheckPermission("subsidy:strativeArea:export")
    @Log(title = "行政区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysStrativeAreaBo bo, HttpServletResponse response) {
        List<SysStrativeAreaVo> list = iSysStrativeAreaService.queryList(bo);
        ExcelUtil.exportExcel(list, "行政区域", SysStrativeAreaVo.class, response);
    }

    /**
     * 获取行政区域详细信息
     *
     * @param id 主键
     */
   // @SaCheckPermission("subsidy:strativeArea:query")
    @GetMapping("/{id}")
    public R<SysStrativeAreaVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSysStrativeAreaService.queryById(id));
    }

    /**
     * 新增行政区域
     */
    //@SaCheckPermission("subsidy:strativeArea:add")
    @Log(title = "行政区域", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysStrativeAreaBo bo) {
        return toAjax(iSysStrativeAreaService.insertByBo(bo));
    }

    /**
     * 修改行政区域
     */
   // @SaCheckPermission("subsidy:strativeArea:edit")
    @Log(title = "行政区域", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysStrativeAreaBo bo) {
        return toAjax(iSysStrativeAreaService.updateByBo(bo));
    }

    /**
     * 删除行政区域
     *
     * @param ids 主键串
     */
   // @SaCheckPermission("subsidy:strativeArea:remove")
    @Log(title = "行政区域", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysStrativeAreaService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
